package cn.edu.hzvtc.controller;


import cn.edu.hzvtc.service.UserService;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jms.Queue;


@RestController
public class UserController {

    @Resource
    UserService userService;

    @Resource
    JmsMessagingTemplate jmsMessagingTemplate;

    @Resource
    Queue queue;




    @PostMapping("/user/add")
    public String addUser(@RequestParam("username") String username, @RequestParam("realname") String realname,
                          @RequestParam("schoolId") String schoolId, @RequestParam("userType") int userType,
                          @RequestParam("password") String password) {
        userService.addUser(username, realname, schoolId, password, userType);
        return "success";
    }

    @PostMapping("/user/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password) {

        jmsMessagingTemplate.convertAndSend(queue,username+" try to login");

        return userService.login(username,password) ?
                "login success":"error username or password";
    }



}
